package com.blue.test;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Snippet {
	
	static String TEST_URL="https://login.dangdang.com/Register.aspx?ReturnUrl=http%3a%2f%2flogin.dangdang.com%2fRegOK.aspx&txtEmail=dsakdl2222as@sina.cn";
	private static void httpClientPost() {
	    HttpClient client = new DefaultHttpClient();
	    HttpPost post = new HttpPost(TEST_URL);
	
	    try {
	        ContentProducer cp = new ContentProducer() {
	            public void writeTo(OutputStream outstream) throws IOException {
	                Writer writer = new OutputStreamWriter(outstream, "UTF-8");
	                writer.write("");
	                writer.flush();
	            }
	        };
	
	        post.setEntity(new EntityTemplate(cp));
	        HttpResponse response = client.execute(post);
	    
	        System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (ClientProtocolException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
	    }
	}
	
	public static void main(String[] args) {
	Snippet.httpClientPost();	
	}
	
}

